﻿using netDxf;
using netDxf.Entities;
using netDxf.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReadWriteSingle
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string dxfFile = @"D:\dl\test.dxf";
            {
                Console.WriteLine(dxfFile);

                try
                {

                    DxfDocument doc = DxfDocument.Load(dxfFile);
                    List< EntityObject > entities = new List< EntityObject >();
                    foreach (Layout layout in doc.Layouts)
                    {
                        foreach (EntityObject entity in doc.Layouts.GetReferences(layout).OfType<EntityObject>())
                        {
                            if (entity.Type == EntityType.Polyline2D)
                            {
                                Polyline2D polyline = entity as Polyline2D;

                                Console.WriteLine(polyline.Vertexes.Count);
                                if(polyline.Vertexes.Count<=2)
                                {
                                    entities.Add(entity);
                                }
                            }
                            
                        }
                    }
                    foreach(EntityObject entity in entities)
                    {
                        doc.Entities.Remove(entity);

                    }
                    doc.Save(@"D:\dl\test_readwrite.dxf");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

            }

            Console.WriteLine("程序结束。");
            Console.ReadKey();
        }
    }
}
